<template>
  <el-dialog width="980px" :title="title" :visible.sync="visible">
    <el-form ref="form" :rules="rules" :model="model" label-width="160px" v-loading="loading">

      <el-form-item label="归还时间" prop="dueDate">
        <el-date-picker
          type="date"
          placeholder="选择日期"
          v-model="model.dueDate"
        ></el-date-picker>
      </el-form-item>
      <el-form-item prop="operator" label="经办人">
        <el-input placeholder="请输入经办人" v-model="model.operator"></el-input>
      </el-form-item>
      <el-form-item prop="phone" label="联系方式">
        <el-input placeholder="请输入联系方式" v-model="model.phone"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>

  import Vue from 'vue'
  import SelectCompany from '@/components/SelectCompany'
  import { MessageBox, Message,Notification } from 'element-ui'
  import pick from 'lodash.pick'
  import { ACCESS_TOKEN } from "@/store/mutation-types"
  import { getAction,deleteAction,putAction,postAction } from '@/api/manage'

  export default {
    name: "renewal",
    components: {SelectCompany
    },
    data () {
      return {
        title:"续期",
        visible: false,
        loading:false,
        multipleSelection: [],
        model: {},
        url: {

        },  // 新增资产表单验证
        rules: {
          dueDate: [{ required: true, message: '请输入归还时间', trigger: 'blur' }],
          operator: [{ required: true, message: '请输入经办人', trigger: 'blur' }],
          phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],


        },
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN);
      this.headers = {"X-Access-Token":token}

    },
    methods: {
      refresh () {

      },
      add (selection) {
        if(selection.length==0){
          this.$message.warning("请选择需要续期的资产信息！");
          return;
        }
        this.refresh();
        this.edit({assetIds: selection.map( row => row.id ),dueDate: selection[0].dueDate});
      },
      edit (records) {
        // this.resetScreenSize(); // 调用此方法,根据屏幕宽度自适应调整抽屉的宽度
        let that = this;
        if(that.$refs.form){
          that.$refs.form.resetFields();
        }
        that.model = Object.assign({}, records);
        //that.form.setFieldsValue(pick(this.model,'username','sex','realname','email','phone','activitiSync','workNo','telephone','post'))
        this.visible = true;
      },

      handleSubmit () {
        const that = this;
        this.$refs.form.validate(valid => {
          if (valid) {
            this.loading = true
            let promise;
            promise = postAction("/retrocede/renew",Object.assign({}, this.model));
            promise.then(res =>{
              if(res.success){
                this.$message.success(res.message)
                that.$emit('ok');
                that.close();
              }else{
                this.$message.warning( res.message)
              }
            }).finally(() => {
              this.loading = false
            });
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
    }
  }
</script>

<style scoped>

</style>
